package com.panshi.controller;

import com.panshi.qa.api.HasbeiQaApp;
import com.panshi.qa.api.vo.*;
import com.panshi.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/qs")
public class QsController {

    @Autowired
    private HasbeiQaApp qaApi;


    //分页查询
    @RequiresPermissions("qa:list:*")
    @PostMapping(value = "/pageQsList",consumes = "application/json")
    public Map<String,Object> pageQaList(@RequestBody QueryVO queryVO){
            ItemQueryVo item = new ItemQueryVo();
            item.setCurrent(queryVO.getPage());
            item.setPageSize(queryVO.getLimit());
            SearchParams searchParams = new SearchParams(queryVO.getTitle(),queryVO.getTypeId(),queryVO.getStatus());
            item.setSearchParams(searchParams);
            System.out.println(item);
            Map<String, Object> map = qaApi.pageQuery(item);
            return map;
    }

    //上下架
    @RequiresPermissions("qa:edit:*")
    @PutMapping
    public R editState(@RequestBody QaQuestion qaQuestion){
       return qaApi.updateQuestion(qaQuestion);
    }

    //查看
    @GetMapping("/{id}")
    public Map<String, Object> getQaInfo(@PathVariable("id")Long id){
        return qaApi.detailSystem(id);
    }

    @GetMapping("/type")
    public String getQaType(){
        return qaApi.thtypeQuery();
    }


//========================uncheck================================

    //分页查询
    @RequiresPermissions("qa:list:*")
    @GetMapping("/un/pageQsUncheckList")
    public Map<String,Object> pageQaUncheckList(Integer page,Integer limit){
            ItemQueryVo item = new ItemQueryVo();
            item.setCurrent(page);
            item.setPageSize(limit);
            Map<String, Object> map = qaApi.itemUncheckQuery(item);
            return map;
    }

    //审核
    @RequiresPermissions("qa:edit:*")
    @PutMapping("/un")
    public R editCheck(@RequestBody QaQuestionUncheck qaQuestionUncheck){
        return qaApi.updateQuestionUncheck(qaQuestionUncheck);
    }

    //删除
    @RequiresPermissions("qa:del:*")
    @DeleteMapping("/un/{id}")
    public R delUncheck(@PathVariable("id")Integer id){
        return qaApi.delUncheckQuestion(id);
    }


}